package com.net.shop.car.manager;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;

/**
 * @description 活动生命控制器
 * @author wangpeng
 * @date 2014-12-20
 */
public class ActivityCollector {

	/** 活动列表容器 */
	public static List<Activity> activities = new ArrayList<Activity>();

	public static void addActivity(Activity activity) {
		if (!activities.contains(activity)) {
			activities.add(activity);
		}
	}

	public static void removeActivity(Activity activity) {
		activities.remove(activity);
	}

	public static void finishActivity(String activityName) {
		// if (activities.contains(activity)) {
		// activity.finish();
		// removeActivity(activity);
		// }
		int size = activities.size();
		
		for (Activity activity : activities) {
           if (activityName.equals(activity.getClass().getSimpleName())) {
        	   activity.finish();
//        	   removeActivity(activity);
           }
		}
	}

	public static int size() {
		return activities.size();
	}

	public static void finishAll() {
		for (Activity activity : activities) {
			if (!activity.isFinishing())
				activity.finish();
		}
		System.exit(0);
	}

}
